package Firepear::Carrot::Util;

use warnings;
use strict;

use Exporter qw(import);

our @ISA = qw(Exporter);
our @EXPORT = qw(commenter status);

=head1 NAME

Firepear::Carrot::Util - Crunchy-sweet Document Authoring!

=head1 VERSION

Version 1.000

=cut

our $VERSION = '1.000';

=head1 SYNOPSIS

This version of Firepear::Carrot is incomplete.

=head1 EXPORTED ROUTINES

=head2 commenter

Checks tokens for comment delineators and handles the comment (that is
to say, "reads to end-of-line) if one is found. C<commenter> consumes
the terminal newline from the point of view of lexer loops.

If no delimiter is found, the original token is returned. If one is
found, the subtoken which preceeds the delimiter will be returned (the
empty string for tokens which begin with a delimiter).

The comment-ending newline is appended to the token before it is
returned unless the comment spans the entire line.

=cut

sub commenter {
    my ($self,$l,$delim) = @_;
    my $token = $l->current;
    my $finfo = $l->fileinfo;

    return $token unless $token =~ /$delim/;

    ($token) = split(/$delim/, $token, 2);
    until ($l->status) {
	my $tok = $l->fetch;
	if ($tok =~ /\n/) {
	    $l->settoken(cur => $token, next => "\n")
	      unless ($finfo->{line}[0] =~ /^$delim/);
	    last;
	}
    }
    return $token;
}

=head2 status

=cut

sub status {
    my ($self,$status) = @_;
    return $self->{s} unless defined $status;
    $self->{s} = $status;
    return $status;
}

=head1 AUTHOR

Shawn Boyette, C<< <mdxi@cpan.org> >>

=head1 BUGS

Please report any bugs or feature requests at
L<http://carrot.googlecode.com/>.  I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.

=head1 COPYRIGHT & LICENSE

Copyright 2008 Shawn Boyette

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of the <ORGANIZATION> nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

=cut

1; # End of Firepear::Carrot::Util
